var rootview = ui("$");
var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var http = require("helper/http");
var circleUrl = require("url/circle");


//图片展示gridView
var do_GridView_1 = ui("do_GridView_1");
var detailDescribe = ui("detailDescribe");
var InforZan = ui("InforZan");
rootview.setMapping({   // 此处的Mapping只能设置在 RootView 上 ;
	"UserName.text" : "creatorName",
    "UserPic.tag" : "creatorId",
    "UserPic.source" : "fullCreatorImg",
    "detailDescribe.text" : "content",
    "InforTime.text" : "cnNewAt",
    "InforReply.text" : "commentCont",
    "InforZan.text" : "praiseCont",
    "do_GridView_1.tag" : "bigImgItems",
    "do_GridView_1.items" : "imgItems",
    "do_GridView_1.visible" : "hasImg",
    "do_ALayout_4.tag" : "id",
    "lableCircleName.text" : "circleName",
    "buttonDel.tag" : "status", //1-正常;2-删除
    "lableHided.tag" : "optUserId",//操作人id
    "do_ALayout_delete.tag" : "isShow" //是否显示:1-是;2-否
});

rootview.on("dataRefreshed", function(){
	var status = ui("buttonDel").tag;//1-正常;2-删除
	var isShow = ui("do_ALayout_delete").tag; //是否显示:1-是;2-否
	var optUserId = ui("lableHided").tag;//操作人id
	if(isShow ==1){
		ui("lableHided").visible = false;
		ui("buttonDel").visible = true;
	}else{
		ui("lableHided").visible = true;
		ui("buttonDel").visible = false;
		if(status == 2){//已删除
			if(optUserId == ui("UserPic").tag){//版主删除
				ui("lableHided").text = "版主已删除";
			}else{//管理员、圈主删除
				ui("lableHided").text = "已被删除";
			}
		}else{
			ui("lableHided").text = "已屏蔽";
		}
		
	}
});

//图片浏览注册事件
do_GridView_1.on("touch", function(data){
	openHelper.open("source://view/reuse/imgBrowser.ui", {
		imgDatas :do_GridView_1.tag,index:data
	});
});

//话题详情
ui("do_LinearLayout_1").on("touch",function(){
	var topicId = ui("do_ALayout_4").tag;
	var status = ui("buttonDel").tag;//1-正常;2-删除
	if(status == 2){//已删除
		nf.toast("话题已删除!");
		return;
	}
	if(topicId != null){
		openHelper.open("source://view/circle/topic/detail/topicBorderView.ui",{topicId:topicId});
	}
})

ui("buttonDel").on("touch",function(){
	nf.confirm("您确实要删除这条记录吗？", "删除", "确定", "取消", function(data, e) {
		if(data == 1){
			delTopic();
		}
	});
});

function delTopic(){
	var params = {
		id: ui("do_ALayout_4").tag
	};
	http.post(circleUrl.url.topic.doDelete, params, function(data) {
		nf.toast("删除成功");
		page.fire("mytopic_deleteTopic",ui("do_ALayout_4").tag);
	});
}